//
//  MainViewController.m
//  Demo
//
//  Created by Tang Boss on 11/12/2017.
//  Copyright © 2017 HandeIdealVison. All rights reserved.
//

#import "MainViewController.h"
#import <HandeAR/HandeARViewController.h>
#import <HandeAR/HandeAR.h>
#import <AVFoundation/AVFoundation.h>
#import <MediaPlayer/MediaPlayer.h>

@interface MainViewController ()
@property (nonatomic , strong) AVAudioPlayer *player;
@end

@implementation MainViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)play:(id)sender {
    NSURL *url = [[NSBundle mainBundle] URLForResource:@"123" withExtension:@"mp3"];
    NSError *error=nil;
    
    AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc]initWithContentsOfURL:url error:&error];
    
    audioPlayer.numberOfLoops=10;
    audioPlayer.volume = 1;
    [audioPlayer prepareToPlay];
    
    self.player = audioPlayer;
    [self.player play];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
- (IBAction)push:(id)sender {
    [HandeAR setLoginStatus:YES];
    [HandeAR setPublishTime:@"2017-12-11 12:01:01"];
    [HandeAR setARResourceURL:@"http://oz513xipu.bkt.clouddn.com/"];
    NSURL *url = [[NSBundle mainBundle] URLForResource:@"annualreport" withExtension:@"json"];
    NSData *data = [NSData dataWithContentsOfURL:url];
    NSString *str = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
    [HandeAR setAnnualReport:str];
//    [HandeAR setLayoutTopHeight:64 bottomHeight:100];
    
    HandeARViewController *vc = [[HandeARViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}

- (IBAction)pause:(id)sender {
    [self.player pause];
}

- (IBAction)resume:(id)sender {
    [self.player play];
}

- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag{
    
    if (player == _player && flag) {
        NSLog(@"播放被完成");
    }
}
-(void)audioPlayerBeginInterruption:(AVAudioPlayer *)player{
    if (player == _player){
        NSLog(@"播放被中断");
    }
}
@end
